<?php
namespace app\api\controller\m2979\auto;

use think\Db;
use service\ApiReturn;
use app\api\controller\Base;
use app\member\service\MemberCache;


class Freechabei extends Base {
                
/**
 *  查询茶杯
 *@create_time  2023-12-08 15:17:121
 */ 
public function get_chabei($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freechabei.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freechabei.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freechabei.is_del', '=', 0]; 
 
    $select_info = array (
  'dancengdanxuan' => 
  array (
    1 => '刘备',
    2 => '关羽',
    3 => '张飞',
  ),
  'type' => 
  array (
    1 => '中杯',
    2 => '大杯',
    3 => '超大杯',
  ),
'member_user' => MemberCache::getUserListToMemberID(MemberID), 
'member_dept' => MemberCache::getDeptListToMemberID(MemberID), 
); 
	$dataList = Db::table('lb_free_chabei')
		->alias('freechabei')
		->leftjoin('lb_free_shubiao freeshubiao', 'freeshubiao.aid = freechabei.freeshubiao_id')
		->field("freeshubiao.wenben as freeshubiao_wenben,freechabei.xitongyuangong,freechabei.xitongbumen,freechabei.duoxuanyuangong,freechabei.duoxuanbumen,freechabei.dancengdanxuan,freechabei.type,freechabei.danchengduoxuan,freechabei.duocengdanxuan,freechabei.duocengduoxuan,freechabei.kaiguan,freechabei.shoujihao")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['xitongyuangong_name'] = $select_info['member_user']["{$infodataList['xitongyuangong']}"] ?? '';
			$infodataList['xitongbumen_name'] = $select_info['member_dept']["{$infodataList['xitongbumen']}"] ?? '';
			$infodataList['duoxuanbumen_name'] = $select_info['member_dept']["{$infodataList['duoxuanbumen']}"] ?? '';
			$infodataList['dancengdanxuan_name'] = $select_info['dancengdanxuan']["{$infodataList['dancengdanxuan']}"] ?? '';
			$infodataList['type_name'] = $select_info['type']["{$infodataList['type']}"] ?? '';
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

}